import java.util.LinkedList;
import java.util.List;

public class Day14 {
    // 用栈操作构建数组
    public List<String> buildArray(int[] target, int n) {
        List<String> list = new LinkedList<>();
        int index = 0;
        for(int num = 1; num <= n && index < target.length; num++) {
            if(target[index] == num) {
                list.add("Push");
                index++;
            } else {
                list.add("Push");
                list.add("Pop");
            }
        }
        return list;
    }

    // 下一个更大元素
    public int[] nextGreaterElement(int[] nums1, int[] nums2) {
        int[] ret = new int[nums1.length];
        for(int i = 0; i < nums1.length; i++) {
            ret[i] = getNextGreater(nums2, nums1[i]);
        }
        return ret;
    }

    private int getIndex(int[] arr, int n) {
        for(int i = 0; i < arr.length; i++) {
            if(arr[i] == n) return i;
        }
        return -1;
    }
    // n 是要查到的数值
    private int getNextGreater(int[] arr, int n) {
        int index = getIndex(arr, n);
        if(index == -1) return -1;
        for(int i = index; i < arr.length; i++) {
            if(arr[i] > n) return arr[i];
        }
        return -1;
    }
}
